﻿SmitearWebGL.Objects.Viewport = {};
	
SmitearWebGL.Objects.Viewport.setRect = function( gl, x, y, width, height )
{
	gl.viewport( x, y, width, height );
}

SmitearWebGL.Objects.Viewport.setClearColor = function( gl, clearColor )
{
	clearColor = clearColor || [0.0, 0.0, 0.0, 1.0];
	gl.clearColor( clearColor[0], clearColor[1], clearColor[2], clearColor[3] );
}

SmitearWebGL.Objects.Viewport.setClearDepth = function( gl, clearDepth )
{
	clearDepth = clearDepth || 1.0;
	gl.clearDepth( clearDepth );
}
	
SmitearWebGL.Objects.Viewport.setClearStencil = function( gl, clearStencil )
{
	clearStencil = clearStencil || 0.0;
	gl.clearStencil( clearStencil );
}

SmitearWebGL.Objects.Viewport.setScissorBox = function( gl, x, y, width, height )
{
	gl.enable( gl.SCISSOR_TEST );
	gl.scissor( x, y, width, height );
}

SmitearWebGL.Objects.Viewport.clear = function( gl, clearBit )
{
	clearBit = clearBit == undefined ? ( SmitearWebGL.Objects.Viewport.ClearBit.colorBufferBit | SmitearWebGL.Objects.Viewport.ClearBit.depthBufferBit ) : clearBit;
	
	var flag = 0;
	if ( ( clearBit & ( 1 << 0 ) ) > 0 )
	{
		flag |= gl.COLOR_BUFFER_BIT;
	}
	if ( ( clearBit & ( 1 << 1 ) ) > 0 )
	{
		flag |= gl.DEPTH_BUFFER_BIT;
	}
	if ( ( clearBit & ( 1 << 2 ) ) > 0 )
	{
		flag |= gl.STENCIL_BUFFER_BIT;
	}
	
	gl.clear( flag );
}

SmitearWebGL.Objects.Viewport.ClearBit = 
{
	colorBufferBit : 1,
	depthBufferBit : 2,
	stencilBufferBit : 4
}